\section{Scientific Computing in Python}

\centeredlargetext{white}{black}{
Scientific Computing in Python
}

\setcounter{ipycommand}{0}

\begin{frame}
\frametitle{NumPy, SciPy, and Matplotlib}
\begin{itemize}
  \item NumPy adds basic MATLAB-like capability to Python:
  \begin{itemize}
    \item multidimensional arrays with homogeneous data types
    \item specific numeric data types (e.g.\ \lstpy{int8}, \lstpy{uint32}, \lstpy{float64})
    \item array manipulation functions (e.g.\ reshape, transpose, concatenate)
    \item array generation (e.g.\ ones, zeros, eye, random)
    \item element-wise math operations (e.g.\ add, multiply, max, sin)
    \item matrix math operations (e.g.\ inner/outer product, rank, trace)
    \item linear algebra (e.g.\ inv, pinv, svd, eig, det, qr)
  \end{itemize}
  \pause
  \item SciPy builds on NumPy (much like MATLAB toolboxes) adding:
  \begin{itemize}
    \item multidimensional image processing
    \item non-linear solvers, optimization, root finding
    \item signal processing, fast Fourier transforms
    \item numerical integration, interpolation, statistical functions
    \item sparse matrices, sparse solvers
    \item clustering algorithms, distance metrics, spatial data structures
    \item file IO (including to MATLAB .mat files)
  \end{itemize}
  \pause
  \item Matplotlib adds MATLAB-like plotting capability on top of NumPy.
\end{itemize}
\end{frame}


\begin{frame}[fragile]
\frametitle{Interactive Scientific Python (aka PyLab)}
\reference{
More info: \url{http://www.scipy.org/PyLab}
}
\begin{itemize}
  \item PyLab is a meta-package that includes NumPy, SciPy, and Matplotlib.
  \item The easiest (and most MATLAB-like) way to work with scientific Python
        is to import everything into the global name space.
\end{itemize}
\begin{lstlisting}
from pylab import *
\end{lstlisting}
\begin{itemize}
  \item IPython can be started with the \texttt{--pylab} command line option.
  \item Spyder starts its standard Python interpreter with these scientific libraries imported,
        much like PyLab, but not PyLab \textit{per se}.
\end{itemize}
\end{frame}


\begin{frame}[fragile]
\frametitle{Scripting with Scientific Python}
\reference{
\url{http://docs.scipy.org/doc/scipy/reference/tutorial/general.html}
}
\begin{itemize}
  \item When writing scripts it is recommended that you:
  \begin{itemize}
    \item only import what you need, for efficiency
    \item import packages into namespaces, to avoid name clashes
  \end{itemize}
  \pause
  \item The community has adopted abbreviated naming conventions:
\end{itemize}
\begin{lstlisting}
import numpy as np
import scipy as sp
import matplotlib as mpl
import matplotlib.pyplot as plt
\end{lstlisting}
\pause
\begin{itemize}
  \item Some different ways of working with NumPy are
\end{itemize}
\begin{lstlisting}
from pylab import *            # Import everything.  Good for interactive work,
svd(eye(3))                    # but not recommended for writing scripts.

from numpy import eye, array   # Import only what you need into the global namespace.
from numpy.linalg import svd   # Verbose syntax for import statements,
svd(eye(3))                    # but simple syntax for calling functions.

import numpy as np             # Import a superset of what you need into a namespace.
np.linalg.svd(np.eye(3))       # More verbose syntax for calling functions.
\end{lstlisting}
\end{frame}


\subsection{NumPy}
\input{section-python-science-numpy}
\subsection{Matplotlib}
\input{section-python-science-matplotlib}
\subsection{SciPy}
\input{section-python-science-scipy}



